package com.example.networkchangedemo.weight;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.networkchangedemo.R;
import com.example.networkchangedemo.adapter.FullVideoDetailAdapter;
import com.example.networkchangedemo.model.VideoDetailModel;

import java.util.List;


/**
 * @author: njb
 * @date: 2022/3/14 17:39
 * @desc: 描述
 */
public class FullVideoPopupWindow extends PopupWindow {
    private List<VideoDetailModel> videoDetails;
    private RecyclerView recyclerView;
    private FullVideoDetailAdapter fullVideoDetailAdapter;
    private Activity context;
    private View view;
    private LinearLayoutManager centerLayoutManager;
    private ConstraintLayout clVideo;

    public FullVideoPopupWindow(@NonNull Activity context, List<VideoDetailModel> videoDetails,int width,int height) {
        super(context);
        this.context = context;
        this.videoDetails = videoDetails;
        view = LayoutInflater.from(context).inflate(R.layout.popup_full_video, null);
        setContentView(view);
        this.setBackgroundDrawable(null);
        setWidth(width);
        setHeight(height);
        setOutsideTouchable(true);
        setTouchable(true);
        initView();
    }

    private void initView() {
        recyclerView = view.findViewById(R.id.rv_full_video);
        clVideo = view.findViewById(R.id.cl_full_root);
        fullVideoDetailAdapter = new FullVideoDetailAdapter(context,videoDetails);
        centerLayoutManager = new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        recyclerView.setAdapter(fullVideoDetailAdapter);
        clVideo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FullVideoPopupWindow.this.dismiss();
            }
        });
    }
}
